﻿

namespace Mulala.Cavan.Domain.MainBoundedContext.MulalaModule
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Mulala.Cavan.Domain.MainBoundedContext.ProprietorModule;
    using Mulala.Cavan.Domain.MainBoundedContext.CorporationModule;
    using Mulala.Cavan.Domain.MainBoundedContext.NannyModule;
    using Mulala.Cavan.Domain.MainBoundedContext.SecurityModule;
    using Mulala.Cavan.Domain.MainBoundedContext.DictionaryModule;

    public class RegistrationService : IRegistrationService
    {
        public ProprietorRegistrationResult RegisterProprietor(
                                                    string name,
                                                    string password,
                                                    string email,
                                                    Area area,
                                                    IList<Role> roles)
        {
            ProprietorRegistrationResult prr = new ProprietorRegistrationResult();

            UserAccount userAccount = UserAccountFactory.CreateUserAccount(name, password, email, roles);
            ProprietorStatus proprietorStatus = ProprietorStatusFactory.CreateProprietorStatus(userAccount.Name);
            Proprietor proprietor = ProprietorFactory.CreateProprietor(userAccount, proprietorStatus, area);

            prr.Object = proprietor;

            return prr;
        }

        public CorporationRegistrationResult RegisterCorporation(
                                                    string name,
                                                    string password,
                                                    string email,
                                                    Area area,
                                                    IList<Role> roles)
        {
            CorporationRegistrationResult crr = new CorporationRegistrationResult();

            UserAccount userAccount = UserAccountFactory.CreateUserAccount(name, password, email, roles);
            CorporationStatus corporationStatus = CorporationStatusFactory.CreateCorporationStatus(name);
            Corporation corporation = CorporationFactory.CreateCorporation(userAccount, area, corporationStatus);

            crr.Object = corporation;

            return crr;
        }

        public NannyRegistrationResult RegisterNanny( 
                                        string name,
                                        string password,
                                        string email,
                                        Area area,
                                        IList<Role> roles,
                                        Corporation corporation)
        {
            UserAccount userAccount = UserAccountFactory.CreateUserAccount(name, password, email, roles);
            NannyStatus nannyStatus = NannyStatusFactory.CreateNannyStatus(name);
            Nanny nanny = NannyFactory.CreateNanny(corporation, userAccount, area, nannyStatus);

            NannyRegistrationResult nrr = new NannyRegistrationResult();
            nrr.Object = nanny;

            return nrr;
        }
    }
}
